package cn.edu.buaa.cnsatm.traffic_big_data_server.highway.dao;

import cn.edu.buaa.cnsatm.traffic_big_data_server.util.JDBCUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
public class HighwayStatusDAO {
    public static ResultSet getTopKHighwayWeatherEffect(int k){
        /**
         * @author: LX
         * @methodName: getTopKHighwayWeatherEffect
         * @description: 查询前k条高速气象影响
         * @data: 2019-11-05
         **/
        String sql = "SELECT block_reason, block_description, block_start_time, block_title FROM road_status WHERE block_reason = '气象' AND road_type = '公路' ORDER BY block_start_time DESC LIMIT " + String.valueOf(k);
        Statement stmt = null;
        ResultSet resultSet = null;
        try {
            stmt = JDBCUtil.databaseConnecttion.createStatement();
            resultSet= stmt.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return resultSet;
    }
    @Deprecated
    public static String getHiwayStatus(int top_num) {
        final String res = "[";
        String temp = "";
        temp += res;
        for (int i = 0; i < top_num; i++) {
            String detail = getDetail(i);
            String[] resList = detail.split(",");
            temp += "{\"tag\":\"" + resList[0] + "\",\"info\":\"" + resList[1] +
                    "\",\"description\":\"" + resList[2] + "\",\"datetime\":\"" + generateDate(i) + "\"},";
        }
        temp = temp.substring(0, temp.length() - 1);
        temp += "]";
        return temp;
    }
    @Deprecated
    public static String generateHiwayStatus() {
        String res = "";
        String tag = "";
        String[] specialTags = {"道路损毁", "道路施工"};
        String weather = "", event = "";
        //按概率产生公路态势标签
        if (Math.random() > 0.95) {
            tag = specialTags[(Math.random() > 0.5 ? 0 : 1)];

        }

        return res;

    }
    @Deprecated
    public static String getName() {
        String[] highwayName = {"青兰高速山西段", "京哈高速河北廊坊段", "京哈高速北京段", "京沪高速上海段",
                "济广高速粤段", "沪陕高速江苏段", "京藏高速河北段", "兰海高速重庆段", "长深高速河北段A", "呼北高速河南段",
                "大广高速湖北段", "汕昆高速贵州段", "沪蓉高速四川段", "沈海高速山东段"};
        return highwayName[(int) (Math.random() * 14)];
    }
    @Deprecated
    public static String generateDate(int time) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("mm");
        //String dateGen = simpleDateFormat.format(date);
        String dateGen = "2019-10-19 15";
        //int mm = Integer.valueOf(simpleDateFormat1.format(date)).intValue();
        int mm = 57;
        dateGen += (":" + (mm > 30 ? mm - time * 3 : mm - time * 3));
        return dateGen;
    }
    @Deprecated
    public static String getDetail(int num) {
        String[] detail = {
                "道路施工,宁波绕城高速西段正在施工,宁波绕城高速西段，九向63k十650路缘石修复，需封闭第一车道进行作业，现已开始。",
                "交通事件,京哈高速京秦段车流量大,京哈高速京秦段榛子镇站，因车流量大，榛子镇站附近沈阳方向车辆缓慢通行约11公里。",
                "交通事故,京承高速交通事故,京承高速出京方向K9黄港桥南发生交通事故，后方车辆行驶缓慢，正在处理中，请注意行车安全。",
                "交通事故,京昆高速西汉段交通事故,京昆高速西汉段汉中方向朱雀立交和秦岭服务区A区临时交通管制。",
                "路线封闭,福银高速西长段临时封闭,福银高速西长段长武方向礼泉、乾陵至陕甘界之间所有收费站入口临时封闭。",
                "道路施工,京哈高速京秦段道路施工,京哈高速京秦段养护施工，与京哈高速京秦段互通唐山方向车辆缓慢通行约5公里。",
                "交通事件,长深高速丰南西站车流量大,长深高速丰南西站，因车流量大，丰南西站附近天津方向车辆缓慢通行约3公里。",
                "交通事故,大广高速京衡段交通事故,大广高速京衡段任丘南站，因任丘南站附近K1443发生交通事故，任丘南站附近北京方向车辆缓慢通行。",
                "交通天气,沪渝高速长万段大雾管制,G50沪渝高速长万段桃花、合兴、云台收费站入口大雾管制，请绕行。",
                "交通事件,张汶高速公路平阿段车流量大,G0611张汶高速公路平阿段，因返回西宁的车流量大，平阿高速K370至K372段(左幅)有压车现象"
        };
        return detail[num];
    }
}
